import UIKit

class MainViewController: UIViewController, DualListViewControllerDelegate, DualListViewControllerDataSource {
  
  @IBOutlet weak var containerView: UIView!
  
  private var categories: [Category] = [
    Category(name: "Category 1", contents: ["Content 1 for Category 1", "Content 2 for Category 1"]),
    Category(name: "Category 2", contents: ["Content 1 for Category 2", "Content 2 for Category 2"]),
    Category(name: "Category 3", contents: ["Content 1 for Category 3", "Content 2 for Category 3"])
  ]
  
  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let dualListVC = segue.destination as? DualListViewController {
      dualListVC.delegate = self
      dualListVC.dataSource = self
    }
  }
  
  // MARK: - DualListViewControllerDataSource Methods
  
  func numberOfCategories() -> Int {
    return categories.count
  }
  
  func categoryAt(index: Int) -> Category {
    return categories[index]
  }
  
  // MARK: - DualListViewControllerDelegate Methods
  
  func didSelectCategory(at index: Int) {
    print("Selected category at index: \(index)")
  }
  
  func didSelectContent(at categoryIndex: Int, contentIndex: Int) {
    let category = categories[categoryIndex]
    let content = category.contents[contentIndex]
    print("Selected content at category \(categoryIndex), content \(contentIndex): \(content)")
  }
}
